package cooccurrence;

import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import utilities.Twokenizer;

public class Cooccurrence {
	
	public static void main(String[] args) throws FileNotFoundException {
		Map<String,Map<String,Integer>> cooc = new HashMap<String,Map<String,Integer>>();
		Parse parse = new Parse();
		Set<String> linee = parse.parseTxt("C:/Users/Marco/workspace/Main/iphone.txt");
		//Set<String> linee = parse.parseTxt("C:/Users/Marco/workspace/Main/ipad.txt");
		//Set<String> linee = parse.parseTxt("C:/Users/Marco/workspace/Main/android.txt");
		//Set<String> linee = parse.parseTxt("C:/Users/Marco/workspace/Main/jobs.txt");
		//Set<String> linee = parse.parseTxt("C:/Users/Marco/workspace/Main/love.txt");
		Iterator<String> iter = linee.iterator();
		List<String> linea;
		Twokenizer tok = new Twokenizer();
		while(iter.hasNext()){
			linea = tok.twokenize(iter.next());
			System.out.println(linea);
			String[] tokens =  linea.toArray(new String[0]);
			String tmp;
			for (int i = 0; i < tokens.length; i++) {
				tmp = tokens[i];
				if(!cooc.containsKey(tmp))
					cooc.put(tmp, new HashMap<String,Integer>());
				for (int j = 0; j < tokens.length; j++) {
					if(j!=i){
						if(cooc.get(tmp).containsKey(tokens[j])){
							Integer occ = cooc.get(tmp).get(tokens[j]);
							cooc.get(tmp).put(tokens[j], new Integer(occ.intValue()+1));
						}
						else
							cooc.get(tmp).put(tokens[j], new Integer(1));
					}
				}
			}
		}
		Set<String> keys = cooc.keySet();
		Iterator<String> it = keys.iterator();
		String key;
		while(it.hasNext()){
			key = it.next();
			System.out.println(key+"---->"+cooc.get(key).toString());
		}
	}

}
